<!DOCTYPE html>
<html lang="zh-cn" class="fullscreen-bg">
<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no">
    <title>后台登录-LayTp极速后台开发框架</title>
    <link href="/favicon.ico" rel="icon">
    <link href="__LIBRARY__/layui/css/layui.css" rel="stylesheet"/>
    <link href="__STATIC__/admin/css/login.css?v=1" rel="stylesheet">
    <!--[if lt IE 9]>
    <script src="__LIBRARY__/html5shiv.min.js"></script>
    <script src="__LIBRARY__/respond.min.js"></script>
    <![endif]-->
    <script type="text/javascript" src="__LIBRARY__/layui/layui.js"></script>
</head>
<body>
<div class="login-wrapper">
    <div class="login-header" align="center">
        {$Think.config.laytp.basic.site_name}
        <img src="__STATIC__/admin/image/LayTp.png">
    </div>
    <form class="layui-form">
        <h2>后台登录</h2>
        <div class="layui-form-item layui-input-icon-group">
            <i class="layui-icon layui-icon-username"></i>
            <input class="layui-input" name="username" placeholder="请输入登录账号" autocomplete="off"
                   lay-verType="tips" lay-verify="required" required value=""/>
        </div>
        <div class="layui-form-item layui-input-icon-group">
            <i class="layui-icon layui-icon-password"></i>
            <input class="layui-input" name="password" id="password" placeholder="请输入登录密码" type="password"
                   lay-verType="tips" lay-verify="required" required value=""/>
        </div>
        <input type="hidden" value="{$referer}" name="referer" id="referer" />
        {if $Think.config.laytp.basic.login_vercode}
        <div class="layui-form-item layui-input-icon-group login-captcha-group">
            <i class="layui-icon layui-icon-auz"></i>
            <input class="layui-input" name="code" id="code" placeholder="请输入验证码" autocomplete="off"
                   lay-verType="tips" lay-verify="required" required/>
            <img class="login-captcha" id="captcha_img" src="/verifyCode" />
        </div>
        {else/}
        <input type="hidden" name="code" value="1"/>
        {/if}
        <div class="layui-form-item">
            <a class="layui-btn layui-btn-normal layui-btn-fluid" id="submitBtn" lay-filter="doLogin" lay-submit>登录</a>
        </div>
    </form>
</div>
<div class="login-footer">
    <p>Copyright © 2020 laytp.com 版权所有</p>
    <p>
        <span><a href="http://www.laytp.com" target="_blank">项目官网</a></span>
        | <span><a href="http://www.laytp.com/bbs" target="_blank">社区交流</a></span>
        | <span><a href="https://gitee.com/junstar/laytp" target="_blank">Gitee仓库</a></span>
        | <span><a href="/admin/auth.login/index_old">原登录界面</a></span>
    </p>
</div>
<script>
    layui.config({
        version: false //一般用于更新模块缓存，默认不开启。设为true即让浏览器不缓存。也可以设为一个固定的值，如：201610
        ,debug: false //用于开启调试模式，默认false，如果设为true，则JS模块的节点会保留在页面
        ,base: '/static/library/layui/extends/' //设定扩展的Layui模块的所在目录，一般用于外部模块扩展
    }).use(['layTp'],function(){
        var $ = layui.jquery;
        var form = layui.form;
        var laytp = layui.layTp;

        $("#captcha_img").click(function(){
            this.src = "/verifyCode?v=" + Math.random();
        });

        form.on('submit(doLogin)', function(obj){
            $.ajax({
                type: 'POST'
                ,url: '/admin/auth.login/do_login'
                ,data: obj.field
                ,dataType: 'json'
                ,success:function(res){
                    if(res['code'] === 1){
                        laytp.facade.setcookie('admin_token', res['data']['admin_token'], 3);
                        laytp.facade.success(res.msg);
                        setTimeout( function(){redirect(res['data']['url'])}, 1000 );
                    }else{
                        laytp.facade.error(res.msg);
                        $('#captcha_img').click();
                    }
                }
                ,error: function (xhr) {
                    laytp.facade.error(xhr['responseJSON']['message']);
                    $('#captcha_img').click();
                }
            });
            return false;
        });

        function redirect(url)
        {
            url = url ? url : "/admin?ref=1";
            location.href = url;
        }

        {if $Think.config.laytp.basic.login_vercode}
        $("#code").focus(function()
        {
            $(document).on("keydown",function(event)
            {
                if( event.keyCode == 13 )
                {
                    $('#submitBtn').click();
                }
            });
            $("#code").unbind();
        });
        {else}
        $("#password").focus(function()
        {
            $(document).on("keydown",function(event)
            {
                if( event.keyCode == 13 )
                {
                    $('#submitBtn').click();
                }
            });
            $("#password").unbind();
        });
        {/if}
    });
</script>
</body>
</html>